import {
  Controller,
  Post,
  Body,
  UseGuards,
  Request,
  Get,
  Delete,
  Put,
  Param,
  Query,
} from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { CreateFormDto } from './dto/create-form.dto';
import { FormService } from './form.service';
import { Form } from './form.entity';
import { RemoveFormDto } from './dto/remove-form.dto';
import { RetrieveFormDto } from './dto/retrieve-form.dto';
import { UpdateFormDto } from './dto/update-form.dto';
import { FindFormDto } from './dto/find-form.dto';
import { JwtAuthGuardUser } from 'src/auth/guards/jwt-auth.guard';

@ApiTags('登记信息')
@Controller('api/form')
export class FormController {
  constructor(private readonly formService: FormService) {}

  // 增加
  // @UseGuards(JwtAuthGuardUser)
  @Post()
  @ApiOperation({ summary: '增加' })
  async create(@Body() createFormDto: CreateFormDto): Promise<Form> {
    return await this.formService.create(createFormDto);
  }

  // 删除
  @UseGuards(JwtAuthGuardUser)
  @Delete()
  @ApiOperation({ summary: '删除' })
  async remove(@Body() removeFormDto: RemoveFormDto): Promise<any> {
    return await this.formService.delete(removeFormDto);
  }

  // 更新
  @UseGuards(JwtAuthGuardUser)
  @Put(':id')
  @ApiOperation({ summary: '更新' })
  async update(
    @Param() params: RetrieveFormDto,
    @Body() updateFormDto: UpdateFormDto,
  ): Promise<any> {
    return await this.formService.update({
      id: params.id,
      updateFormDto,
    });
  }

  // 列表
  // @UseGuards(JwtAuthGuard)
  @Get()
  @ApiOperation({ summary: '列表' })
  async findAll(@Query() query: FindFormDto): Promise<Form> {
    return await this.formService.findAll(query);
  }

  // 根据 id 查找
  @Get(':id')
  @ApiOperation({ summary: '根据 id 查找' })
  async findOneById(@Param() params: RetrieveFormDto): Promise<any> {
    return await this.formService.findOneById(params.id);
  }

  // 数量
  @Get('list/count')
  @ApiOperation({ summary: '用户数量' })
  async getCount(@Query() query: FindFormDto) {
    return await this.formService.getCount(query);
  }
}
